package edu.sctu.zhengsenwen.month201506.day20150612;

import java.util.Calendar;
import java.awt.*;

/**
 *
 * 在屏幕上显示时间，每隔一秒刷新一次。
 * Created by user15 on 2015/6/12.
 */
public class Clock implements Runnable {

    public static void main(String[] args) {

    }

    Thread clockThread = null;

    Graphics graphics = null;





    public void init(){

        Font font = new Font("TimeRome", Font.BOLD, 32);
    }




    public void start(){
        if(clockThread!=null){

            clockThread = new Thread(this,"Show time");

            clockThread.start();
        }
    }



    @Override
    public void run() {


        while(clockThread !=null) {


            repaint(graphics);


                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
        }
    }




    private void repaint(Graphics graphics) {

        Font font = null;

        graphics.setFont(font);

        graphics.setColor(Color.blue);

        graphics.drawString(Calendar.HOUR+":"+Calendar.MINUTE+":"+Calendar.SECOND,50,100);
    }



    public void stop(){

       Thread.interrupted();
    }

}
